package com.pro.framework.generator.main.translate;

import java.io.*;
import java.nio.file.*;
import java.util.stream.Stream;

public class BusinessExceptionFinder {

    public static void main(String[] args) throws IOException {
        String[] baseDirs = {
            "D:\\lzb\\baoyi-cloud\\framework-cloud",
            "D:\\lzb\\baoyi-cloud\\parent-cloud",
            "D:\\lzb\\baoyi-cloud\\platform"
        };

        for (String baseDir : baseDirs) {
            Files.walk(Paths.get(baseDir))
                .filter(path -> Files.isRegularFile(path))
                .filter(path -> path.toString().endsWith(".java"))
                .filter(path -> !path.toString().contains(File.separator + "target" + File.separator))
                .forEach(BusinessExceptionFinder::scanFile);
        }
    }

    private static void scanFile(Path filePath) {
        try (BufferedReader reader = new BufferedReader(new FileReader(filePath.toFile()))) {
            String line;
            int lineNumber = 0;
            while ((line = reader.readLine()) != null) {
                lineNumber++;
                if (line.contains("BusinessException(")) {
                    System.out.printf("%s%n",line.trim());
//                    System.out.printf("%s:%d: %s%n", filePath.toString(), lineNumber, line.trim());
                }
            }
        } catch (IOException e) {
            System.err.println("Error reading file: " + filePath);
            e.printStackTrace();
        }
    }
}
